package com.freewater.library.lending.dailysheet.model;

import com.freewater.library.catalogue.model.Book;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDate;

/**
 * 每日借出的书数量
 */
@Data
@Entity
@NoArgsConstructor
@Table(name = "daily_checked_out_count",
        uniqueConstraints = {
                @UniqueConstraint(columnNames = {"isbn", "day"})
        })
@EqualsAndHashCode(of = {"isbn", "day"})
public class DailyCheckedOutCount {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    /**
     * 书ISBN
     */
    private String isbn;
    /**
     * 日期
     */
    @Column(name = "`day`")
    private LocalDate day;
    /**
     * 标题
     */
    private String title;
    /**
     * 副标题
     */
    private String subtitle;
    /**
     * 作者
     */
    private String author;
    /**
     * 出版社
     */
    private String publishingHouse;
    /**
     * 封面图
     */
    private String cover;
    /**
     * 丛书
     */
    private String series;
    /**
     * 借出数量
     */
    private int checkedOutCount;

    public DailyCheckedOutCount(Book book, LocalDate day) {
        this.isbn = book.getIsbn();
        this.day = day;
        this.title = book.getTitle();
        this.subtitle = book.getSubtitle();
        this.author = book.getAuthor();
        this.publishingHouse = book.getPublishingHouse();
        this.cover = book.getCover();
        this.series = book.getSeries();
        this.checkedOutCount = 1;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Unique implements Serializable {
        /**
         * 书ISBN
         */
        private String isbn;
        /**
         * 日期
         */
        private LocalDate day;
    }
}
